package com.huirui.server.controller.mini.program;

import com.huirui.server.pojo.dto.ProductSearchDto;
import com.huirui.server.pojo.result.PageResult;
import com.huirui.server.pojo.result.Result;
import com.huirui.server.pojo.vo.ProductBriefInfoVo;
import com.huirui.server.pojo.vo.SearchLogVo;
import com.huirui.server.service.SearchLogService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/search")
@Slf4j
@Validated
@Tag(name = "搜索管理", description = "微信小程序用户搜索相关")
public class SearchController {

    @Resource
    private SearchLogService searchLogService;

    @GetMapping("/top/items")
    @Operation(summary = "近一个月内的前十大热搜")
    public Result<List<SearchLogVo>> listTopSearches() {
        List<SearchLogVo> list = searchLogService.listTopSearches();
        return Result.success(list);
    }

    @GetMapping("/comprehensive")
    @Operation(summary = "综合搜索")
    public Result<PageResult<ProductBriefInfoVo>> listProductsByComprehensive(@Valid ProductSearchDto productSearchDto) {
        PageResult<ProductBriefInfoVo> res = searchLogService.listProductsByComprehensive(productSearchDto);
        return Result.success(res);
    }

    @GetMapping("/sales")
    @Operation(summary = "根据销量搜索")
    public Result<PageResult<ProductBriefInfoVo>> listProductsBySales(@Valid ProductSearchDto productSearchDto) {
        PageResult<ProductBriefInfoVo> res = searchLogService.listProductsBySales(productSearchDto);
        return Result.success(res);
    }

    @GetMapping("/price")
    @Operation(summary = "根据价格搜索")
    public Result<PageResult<ProductBriefInfoVo>> listProductsByPrice(@Valid ProductSearchDto productSearchDto) {
        PageResult<ProductBriefInfoVo> res = searchLogService.listProductsByPrice(productSearchDto);
        return Result.success(res);
    }

    @GetMapping("/time")
    @Operation(summary = "根据发布时间搜索")
    public Result<PageResult<ProductBriefInfoVo>> listProductsByTime(@Valid ProductSearchDto productSearchDto) {
        PageResult<ProductBriefInfoVo> res = searchLogService.listProductsByTime(productSearchDto);
        return Result.success(res);
    }
}
